extends CenterContainer


onready var sprite_op = $PanelContainer/VBoxContainer/sprite/SpriteSelectPlus
onready var star_probability_input = $PanelContainer/VBoxContainer/star_probability/SpinBox
onready var fish_level_input = $PanelContainer/VBoxContainer/fish_level/SpinBox
onready var single_probability_input = $PanelContainer/VBoxContainer/probability/SpinBox
onready var mutil_probability_input = $PanelContainer/VBoxContainer/probability/SpinBox2
onready var single_low_level_input = $PanelContainer/VBoxContainer/low_level/SpinBox
onready var mutil_low_level_input = $PanelContainer/VBoxContainer/low_level/SpinBox2
onready var single_hight_level_input = $PanelContainer/VBoxContainer/hight_level/SpinBox
onready var mutil_hight_level_input = $PanelContainer/VBoxContainer/hight_level/SpinBox2
onready var single_auto_level_op = $PanelContainer/VBoxContainer/auto_level/OptionButton
onready var mutil_auto_level_op = $PanelContainer/VBoxContainer/auto_level/OptionButton2



var edit_data = null
var area_id = null




func set_edit_data(edit_data, area_id):
	self.edit_data = edit_data
	self.area_id = area_id
	
	if edit_data:
		sprite_op.set_value(edit_data["pokeId"])
		star_probability_input.value = edit_data["starProbability"] 
		fish_level_input.value = edit_data["fishLevel"]
		
		single_probability_input.value = edit_data["probability"]
		mutil_probability_input.value = edit_data["mutilProbability"]
		
		single_low_level_input.value = edit_data["singleLowLevel"]
		mutil_low_level_input.value = edit_data["mutilLowLevel"]
		
		single_hight_level_input.value = edit_data["singleHightLevel"]
		mutil_hight_level_input.value = edit_data["mutilHightLevel"] 
		
		single_auto_level_op.select(single_auto_level_op.get_item_index(edit_data["singleAutoLevel"]))
		mutil_auto_level_op.select(mutil_auto_level_op.get_item_index(edit_data["mutilAutoLevel"]))
	
		$PanelContainer/VBoxContainer/modalTitle.text = "编辑精灵分布"
	else:
		pass



func _on_ok_button_up():
	var map_view = MainTool.getUILayer().get_ui("MapView")
	
	var position_info = map_view.get_select_position_info()
	
	if edit_data:	
		read_form(edit_data)
		
		DataSource.update_data(DataSource.map_sprite_area_item, edit_data)
		
	else:
		var data = {
			"pokeAreaId": area_id,
			"mapId": position_info["map_register"]["id"]
		}
		
		read_form(data)
		
		DataSource.add_data(DataSource.map_sprite_area_item, data)
	
	MainTool.toast_info("更新区域信息成功!")
	
	map_view.sprite_area_update()
	
	MainTool.getUILayer().pop_ui()


func read_form(dic):
	dic["pokeId"] = sprite_op.get_value()
	dic["starProbability"] = star_probability_input.value
	dic["fishLevel"] = fish_level_input.value
	
	dic["probability"] = single_probability_input.value
	dic["mutilProbability"] = mutil_probability_input.value
	
	dic["singleLowLevel"] = single_low_level_input.value
	dic["mutilLowLevel"] = mutil_low_level_input.value
	
	dic["singleHightLevel"] = single_hight_level_input.value
	dic["mutilHightLevel"] = mutil_hight_level_input.value
	
	dic["singleAutoLevel"] = single_auto_level_op.get_selected_id()
	dic["mutilAutoLevel"] = mutil_auto_level_op.get_selected_id()

func _on_cancel_button_up():
	MainTool.getUILayer().pop_ui()
